package io.renren.modules.erp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.erp.entity.BaseParamEntity;
import io.renren.modules.erp.service.BaseParamService;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-07-19 22:30:09
 */
@RestController
@RequestMapping("erp/baseparam")
public class BaseParamController {
    @Autowired
    private BaseParamService baseParamService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erp:baseparam:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = baseParamService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{baseParamId}")
    @RequiresPermissions("erp:baseparam:info")
    public R info(@PathVariable("baseParamId") Long baseParamId){
        BaseParamEntity baseParam = baseParamService.selectById(baseParamId);

        return R.ok().put("baseParam", baseParam);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erp:baseparam:save")
    public R save(@RequestBody BaseParamEntity baseParam){
        baseParamService.insert(baseParam);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erp:baseparam:update")
    public R update(@RequestBody BaseParamEntity baseParam){
        ValidatorUtils.validateEntity(baseParam);
        baseParamService.updateAllColumnById(baseParam);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erp:baseparam:delete")
    public R delete(@RequestBody Long[] baseParamIds){
        baseParamService.deleteBatchIds(Arrays.asList(baseParamIds));

        return R.ok();
    }
    
    /**
     * 信息
     */
    @RequestMapping("/findInfoByCode")
    @RequiresPermissions("erp:baseparam:list")
    public R selectByCode(@RequestParam("paramCode") String paramCode){
        List<BaseParamEntity> baseParamList = baseParamService.selectByCode(paramCode);

        return R.ok().put("list", baseParamList);
    }

}
